{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ea8febdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.globals import ThemeType\n",
    "image_path='images/logo.png'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c3819ead",
   "metadata": {},
   "outputs": [],
   "source": [
    "df=pd.read_excel('D:/校园霸凌相关数据统计/2011年至今校园霸凌搜索指数数据统计.xlsx')\n",
    "dg=df.sort_index(ascending=False)\n",
    "x_data=dg['年份'].to_list() \n",
    "y_data1=dg['用户搜索'].to_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4e8f2c8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "z=(\n",
    "    Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(x_data) \n",
    "    .add_yaxis(\"用户搜索\" ,y_axis=y_data1,itemstyle_opts=opts.ItemStyleOpts(color=\"#b51416\"))\n",
    "    .reversal_axis()\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='2011年至今\"校园霸凌\"搜索指数'),\n",
    "                     xaxis_opts=opts.AxisOpts(name=\"全年搜索指数\"),\n",
    "                     yaxis_opts=opts.AxisOpts(name=\"年份\"),\n",
    "                     datazoom_opts=[opts.DataZoomOpts(orient='vertical')],\n",
    "                     graphic_opts=[\n",
    "                         opts.GraphicImage(\n",
    "                             graphic_item=opts.GraphicItem(\n",
    "                                 id_=\"logo\",right=5,top=5,z=-10,bounding=\"raw\",origin=[75, 75]\n",
    "                             ),\n",
    "                             graphic_imagestyle_opts=opts.GraphicImageStyleOpts(\n",
    "                                 image=image_path,\n",
    "                                 width=150,\n",
    "                                 height=130,\n",
    "                                 opacity=0.4,\n",
    "                             ),\n",
    "                         )\n",
    "                     ],\n",
    "                    )\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "74510988",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"7fbd3cf5684745b9a00bcf73dc931154\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_7fbd3cf5684745b9a00bcf73dc931154 = echarts.init(\n",
       "                    document.getElementById('7fbd3cf5684745b9a00bcf73dc931154'), 'dark', {renderer: 'canvas'});\n",
       "                var option_7fbd3cf5684745b9a00bcf73dc931154 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u7528\\u6237\\u641c\\u7d22\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                12410,\n",
       "                5124,\n",
       "                18615,\n",
       "                28105,\n",
       "                65700,\n",
       "                94062,\n",
       "                135780,\n",
       "                136875,\n",
       "                223380,\n",
       "                215574,\n",
       "                292730,\n",
       "                419750,\n",
       "                475230,\n",
       "                400480\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"color\": \"#b51416\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u7528\\u6237\\u641c\\u7d22\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u5168\\u5e74\\u641c\\u7d22\\u6307\\u6570\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u5e74\\u4efd\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2011\\u5e74\",\n",
       "                \"2012\\u5e74\",\n",
       "                \"2013\\u5e74\",\n",
       "                \"2014\\u5e74\",\n",
       "                \"2015\\u5e74\",\n",
       "                \"2016\\u5e74\",\n",
       "                \"2017\\u5e74\",\n",
       "                \"2018\\u5e74\",\n",
       "                \"2019\\u5e74\",\n",
       "                \"2020\\u5e74\",\n",
       "                \"2021\\u5e74\",\n",
       "                \"2022\\u5e74\",\n",
       "                \"2023\\u5e74\",\n",
       "                \"2024\\u5e74\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"2011\\u5e74\\u81f3\\u4eca\\\"\\u6821\\u56ed\\u9738\\u51cc\\\"\\u641c\\u7d22\\u6307\\u6570\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"type\": \"slider\",\n",
       "            \"showDetail\": true,\n",
       "            \"showDataShadow\": true,\n",
       "            \"realtime\": true,\n",
       "            \"start\": 20,\n",
       "            \"end\": 80,\n",
       "            \"orient\": \"vertical\",\n",
       "            \"zoomLock\": false,\n",
       "            \"filterMode\": \"filter\"\n",
       "        }\n",
       "    ],\n",
       "    \"graphic\": [\n",
       "        {\n",
       "            \"type\": \"image\",\n",
       "            \"id\": \"logo\",\n",
       "            \"$action\": \"merge\",\n",
       "            \"rotation\": 0,\n",
       "            \"origin\": [\n",
       "                75,\n",
       "                75\n",
       "            ],\n",
       "            \"right\": 5,\n",
       "            \"top\": 5,\n",
       "            \"bounding\": \"raw\",\n",
       "            \"z\": -10,\n",
       "            \"zlevel\": 0,\n",
       "            \"silent\": false,\n",
       "            \"invisible\": false,\n",
       "            \"ignore\": false,\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"draggable\": false,\n",
       "            \"progressive\": false,\n",
       "            \"width\": 0,\n",
       "            \"height\": 0,\n",
       "            \"style\": {\n",
       "                \"image\": \"images/logo.png\",\n",
       "                \"x\": 0,\n",
       "                \"y\": 0,\n",
       "                \"width\": 150,\n",
       "                \"height\": 130,\n",
       "                \"opacity\": 0.4\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_7fbd3cf5684745b9a00bcf73dc931154.setOption(option_7fbd3cf5684745b9a00bcf73dc931154);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x2a6d8493fd0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z.render_notebook()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
